package com.studentServer.controller;


import com.studentServer.bean.Comment;
import com.studentServer.dao.CommentDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    CommentDao commentDao;

    @RequestMapping("/add")
    @ResponseBody
    public Map addComment(@RequestBody Comment comment) {
        Map map = new HashMap();
        Comment comment1 = commentDao.saveAndFlush(comment);
        if (comment1 != null) {
            map.put("success", true);
            map.put("message", "发表评论成功!");
        } else {
            map.put("success", false);
            map.put("message", "发表评论失败!");
        }
        return map;
    }
}
